﻿using System;
using NUnit.Framework;

namespace Duhking.Tests
{
    [TestFixture]
    public class StandardMethodFinderTests : MethodFinderTestBase
    {
        private StandardMethodFinder _finder;
        public interface ITestMethodFinder
        {
            void VoidMethod();
            int IntReturnValueMethod();
            void SingleParameterMethod(int param);
        }

        public class MethodFinderTester
        {
            public void VoidMethod()
            {}

            public int IntReturnValueMethod()
            {
                return default(int);
            }

            public void SingleParameterMethod(int param)
            {}
        }

        [SetUp]
        public void Setup()
        {
            _finder = new StandardMethodFinder();
        }

        [Test]
        public void FindMatchingMethod_Returns_MethodInfo_For_MatchingMethod_With_No_Parameters()
        {
            var interfaceMethod = GetMethodInfo("VoidMethod", typeof(ITestMethodFinder));
            var targetMethod = _finder.FindMatchingMethod(interfaceMethod, typeof(MethodFinderTester));
            Assert.That(targetMethod, Is.Not.Null);
            Assert.That(targetMethod, Is.SameAs(GetMethodInfo("VoidMethod",typeof(MethodFinderTester))));
        }

        [Test]
        public void FindMatchingMethod_Returns_MethodInfo_For_MatchingMethod_With_ReturnValue()
        {
            var interfaceMethod = GetMethodInfo("IntReturnValueMethod", typeof(ITestMethodFinder));
            var targetMethod = _finder.FindMatchingMethod(interfaceMethod, typeof(MethodFinderTester));
            Assert.That(targetMethod, Is.Not.Null);
            Assert.That(targetMethod, Is.SameAs(GetMethodInfo("IntReturnValueMethod",typeof(MethodFinderTester))));
        }
    }
}
